<?php

namespace app\admin\model;

use think\Model;

class MessageBoard extends Model
{

    // 表名
    protected $name = 'message_board';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'affiliated_center_text'
    ];

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    
    public function getAffiliatedCenterTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['affiliated_center_id']) ? $data['affiliated_center_id'] : '');
        $list  = db('affiliated_center')->column('id,name');
        return isset($list[$value]) ? $list[$value] : '';
    }
}
